package utils;


public class UrlParamUtil {
//	+    URL 中+号表示空格                                 %2B   
//	空格 URL中的空格可以用+号或者编码           %20 
//	/   分隔目录和子目录                                     %2F     
//	?    分隔实际的URL和参数                             %3F     
//	%    指定特殊字符                                          %25     
//	#    表示书签                                                  %23     
//	&    URL 中指定的参数间的分隔符                  %26     
//	=    URL 中指定参数的值                                %3D
	
	public static String changURl(String str) {
		if (str.indexOf("%")!=-1) {
			str=str.replace("%", "%25");
		}
		if (str.indexOf("+")!=-1) {
			str=str.replace("+", "%2B");
		}
		/*if (str.indexOf("\\")!=-1){
			str=str.replace("\\", " %2F");
		}*/
		if (str.indexOf("?")!=-1) {
			str=str.replace("?", "%3F");
		}
		if (str.indexOf("#")!=-1) {
			str=str.replace("#", "%23");
		}
		if (str.indexOf("&")!=-1) {
			str=str.replace("&", "%26");
		}
		if (str.indexOf("=")!=-1){
			str=str.replace("=", "%3D");
		}
		return str;
	}
	
	/*public static String jointUrl(String url,Map<String, String> paramerts){
		StringBuilder urParamerts = new StringBuilder();
		if (url.indexOf("?")==-1){
			url+="?";
		}
		else{
			url+="&";
		}
		for (Map.Entry<String, String> mapEntry : paramerts.entrySet()) {
			urParamerts.append(mapEntry.getKey()+"="+mapEntry.getValue()+"&");
		}
		String newUrl=url+urParamerts.toString();
		newUrl=newUrl.substring(0, newUrl.length()-1);
		return newUrl;
		
	}
	public static String doRequest(String tourl) throws IOException{
		URL url = new URL(tourl);
		URLConnection con = url.openConnection();
		con.setAllowUserInteraction(false);
		InputStream msgStream = con.getInputStream();
		BufferedReader rd = new BufferedReader(new InputStreamReader(msgStream, "UTF-8"));
		StringBuilder tempStr = new StringBuilder();
		while (rd.read() != -1) {
			tempStr.append(rd.readLine());
		}
		rd.close();
		msgStream.close();
		return null;
		
	}*/
	
	/*public static void main(String[] args) {
		System.out.println(changURl("ghfg?js?gjs/ghdksh/gjs#kjg+gkl#sjg=jds&kg&j+"));
		
	}
*/
}